home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************************************
- * Name: Transfer - Calculate the time elapsed for transfering or riceiving a file *
- * Author: Alessandro Marinuzzi - [Alecos] - http://alecos.altervista.org/ *
- * Purpose: Simulate the transfer of a file obtaining the time elapsed *
- * Usage: Open a shell and type "Transfer" *
- * Bugs: No bug known - This program has been tested severely *
- * Compiler: Sas/C - GNU C++ *
- * Date: 08.04.2000 *
- * Version: 1.0 *
- * Revision: 0.0 *
- ***************************************************************************************************/
-
- #include <iostream.h>
-
- long int file_bytes; // File that you have to transfer in Bytes
- long int speed_bytes; // MegaBytes, KiloBytes or Bytes/Sec transfered
- int bytes_total; // Number of Bytes to transfer each second
- int counter_bytes; // Groups of Bytes for each second elapsed
- int file_size; // Input - Size of the file
- char identifier; // Input - Identifier (M = MegaBytes, K = KiloBytes, B = Bytes)
- char specifier; // Input - Specifier (M = MegaBytes, K = KiloBytes, B = Bytes)
- int counter_seconds; // Time elapsed in seconds
- int seconds_real; // Real time elapsed in seconds
- int rest_seconds; // Real time elapsed as rest in seconds out the minute
- int minutes_real; // Real time elapsed in minutes
- int rest_minutes; // Real time elapsed as rest in minutes out the hour
- int hours_real; // Time elapsed in hours
- int rest_hours; // Real time elapsed as rest in hours out the day
- int days_real; // Real time elapsed in days
- char choice; // Quit or go on with the program
- static const char version[] = "$VER: Transfer 1.0 (08.04.2000) By Alecos"; // Version of the program
-
- main ()
-
- {
- // Infos about the usage
- cout << "Transfer V. 1.0 - Date: 08.04.2000 - by Alessandro Marinuzzi [Alecos]\n";
- cout << "This program simulates the transfer of a file giving you infos about the time elapsed\n";
- while (1) { // Starts an infinite loop
- /****************************/
- /* Initialization Section */
- /****************************/
- file_bytes = 0; // Sets the variable with the value 0 for each loop
- speed_bytes = 0; // Sets the variable with the value 0 for each loop
- counter_bytes = 0; // Sets the variable with the value 0 for each loop
- bytes_total = 0; // Sets the variable with the value 0 for each loop
- file_size = 0; // Sets the variable with the value 0 for each loop
- counter_seconds = 0; // Sets the variable with the value 0 for each loop
- seconds_real = 0; // Sets the variable with the value 0 for each loop
- rest_seconds = 0; // Sets the variable with the value 0 for each loop
- minutes_real = 0; // Sets the variable with the value 0 for each loop
- rest_minutes = 0; // Sets the variable with the value 0 for each loop
- hours_real = 0; // Sets the variable with the value 0 for each loop
- rest_hours = 0; // Sets the variable with the value 0 for each loop
- days_real = 0; // Sets the variable with the value 0 for each loop
- /************************/
- /* Input&Data Section */
- /************************/
- // Insert and store the values
- cout << "Set the transfer rate first - Bytes/Seconds\n";
- cout << "Rate: must be a number bigger than 0 - Specifier: M = MegaBytes, K = KiloBytes, B = Bytes\n";
- cout << "Example: rate = 5 - Specifier = K -> 5120 Bytes/second\n";
- cout << "Rate: "; // Asks for the speed
- cin >> speed_bytes; // Stores the speed
- cout << "Specifier: "; // Specify the speed (MegaBytes, KiloBytes o Bytes)
- cin >> identifier; // Stores the specifier
- switch (identifier) { // Verify if this specifier is allowed
-
- case 'M':
- case 'm':
- // Verify if we manage MegaBytes
- bytes_total = speed_bytes * 1024 * 1024; // Calculating in Bytes
- // Calculating...
- cout << "Transfer rate: " << bytes_total << " Bytes/second !\n";
- break;
-
- case 'K':
- case 'k':
- // Verify if we manage KiloBytes
- bytes_total = speed_bytes * 1024; // Calculating in Bytes
- // Calculating...
- cout << "Transfer rate: " << bytes_total << " Bytes/second !\n";
- break;
-
- case 'B':
- case 'b':
- // Verify if we manage Bytes
- bytes_total = speed_bytes; // Calculating in Bytes
- // Calculating...
- cout << "Transfer rate: " << bytes_total << " Bytes/second !\n";
- break;
-
- default:
- // If the specifier isn't M or K or B - Error !
- cout << "Specifier not allowed ! - Try again !\n"; // Warning message
- continue;
- }
- cout << "Insert the File and the Specifier (M = MegaBytes, K = KiloBytes, B = Bytes)\n";
- cout << "Example: ----- File = 400 ----- Specifier = M ----- [The result is 400 MB]\n"; // Example
- cout << "File: "; // Asks for the file
- cin >> file_size; // Stores the file
- cout << "Specifier: "; // Asks for the specifier
- cin >> specifier; // Stores the specifier
- switch (specifier) { // Verify if this specifier is allowed
-
- case 'M':
- case 'm':
- // Verify if we manage MegaBytes
- file_bytes = file_size * 1024 * 1024; // Calculating in Bytes
- // Calculating...
- cout << "File: " << file_size << " MegaBytes = " << file_bytes << " Bytes !\n";
- cout << "Please wait. I'm simulating the transfer...\n"; // Goes on with the simulation...
- break;
-
- case 'K':
- case 'k':
- // Verify if we manage KiloBytes
- file_bytes = file_size * 1024; // Calculating in Bytes
- // Calculating...
- cout << "File: " << file_size << " KiloBytes = " << file_bytes << " Bytes !\n";
- cout << "Please wait. I'm simulating the transfer...\n"; // Goes on with the simulation...
- break;
-
- case 'B':
- case 'b':
- // Verify if we manage Bytes
- file_bytes = file_size; // Calculating in Bytes
- // Calculating...
- cout << "File: " << file_size << " Bytes = " << file_bytes << " Bytes !\n";
- cout << "Please wait. I'm simulating the transfer...\n"; // Goes on with the simulation...
- break;
-
- default:
- // If the specifier isn't M or K or B - Error !
- cout << "Specifier not allowed ! - Try again !\n"; // Warning message
- continue;
- }
- /******************************/
- /* Verify&Calculate Section */
- /******************************/
- if (bytes_total >= file_bytes) { // If the file transfered is smaller than the speed - Error !
- cout << "Error ! You cannot transfer a file smaller than the transfer rate !!!\n";
- cout << "Try again !\n";
- continue;
- }
- else { // If the file transfered is bigger than the speed - OK !
- while (counter_bytes < file_bytes) { // Starts another loop for determining the time elapsed
- counter_bytes += bytes_total; // + Bytes for each loop for reaching file_bytes
- ++counter_seconds; // Adds 1 for each loop
- seconds_real = counter_seconds; // Renames the variable for a better code
- if (seconds_real >= 60) { // If seconds_real is equal or bigger than 60
- minutes_real = (seconds_real / 60); // Obtains the minutes in integer
- rest_seconds = (seconds_real % 60); // Obtains the rest of the minutes in seconds
- }
- if (minutes_real >= 60) { // If minutes_real is equal or bigger than 60
- hours_real = (seconds_real / 3600); // Obtains the hours in integer
- rest_minutes = (seconds_real % 3600); // Obtains the rest of the hours in minutes
- if (rest_minutes >= 60) { // If the rest of the hours is equal or bigger than 60
- rest_minutes /= 60; // Obtains the rest in minutes properly
- }
- }
- if (hours_real >= 24) { // If hours_real is equal or bigger than 24
- days_real = (seconds_real / 86400); // Obtains the days in integer
- rest_hours = (seconds_real % 86400); // Obtains the rest of the days in hours
- if (rest_hours >= 24) { // If the rest of the hours is equal or bigger than 24
- rest_hours /= 3600; // Obtains the rest in hours properly
- }
- }
- }
- }
- /*********************************/
- /* Result&Print Section */
- /*********************************/
- cout << "File transfered: " << file_bytes << " Bytes\n"; // Infos about the file
- cout << "Time elapsed: "; // Prepares the infos for printing
- if (days_real > 0) { // Verify if there are days for calculating the time elapsed
- cout << " -> " << days_real << " days "; // Prints the days elapsed
- cout << " -> " << rest_hours << " hours "; // Prints the hours elapsed
- cout << " -> " << rest_minutes << " minutes "; // Prints the minutes elapsed
- cout << " -> " << rest_seconds << " seconds\n"; // Prints the seconds elapsed
- }
- if ((hours_real > 0) && (hours_real < 24)) { // Verify if there are hours for calculating the time elapsed
- cout << " -> " << hours_real << " hours "; // Print the hours elapsed
- cout << " -> " << rest_minutes << " minutes "; // Print the minutes elapsed
- cout << " -> " << rest_seconds << " seconds\n"; // Print the seconds elapsed
- }
- if ((minutes_real > 0) && (minutes_real < 60)) { // Verify if there are minutes for calculating the time elapsed
- cout << " -> " << minutes_real << " minutes "; // Print the minutes elapsed
- cout << " -> " << rest_seconds << " seconds\n"; // Prints the seconds elapsed
- }
- if ((seconds_real > 0) && (seconds_real < 60)) { // Verify if there are seconds for calculating the time elapsed
- cout << " -> " << seconds_real << " seconds\n"; // Prints the seconds elapsed
- }
- // Asks a choice: quit or go on !
- cout << "Do you want quit ? - Press Q or q - To go on any key. Key: ";
- cin >> choice; // Stores the choice
- if ((choice == 'Q') || (choice == 'q')) { // By pressing Q or q the program stops working !
- cout << "Quitted !\n";
- break;
- }
- else { // Goes on with the program restarting again the loop
- continue;
- }
- }
-
- return (0);
- }
-
-